﻿
#ifndef CONFIG_H
#define CONFIG_H

//{{{ file documentation -------------------------------------------------------

/*!
 * @file     config.h
 * @brief    dicodor configuration class declaration
 */

//}}} --------------------------------------------------------------------------
//{{{ includes / predeclarations -----------------------------------------------

// @(#) $Id: config.h 50 2012-05-21 12:47:32Z nsouchon-dico@altern.org $

#include <QtCore/QSettings>
#include <QtCore/QDir>
#include <QtCore/QDebug>

#include <QtGui/QApplication>
#include <QtGui/QIcon>

//}}} --------------------------------------------------------------------------
//{{{ structures ---------------------------------------------------------------
//}}} --------------------------------------------------------------------------
//{{{ .Config ------------------------------------------------------------------

//{{{ class documentation ------------------------------------------------------

/*!
 * @class    Config
 * @brief    dicodor configuration class
 *
 *           defines all what is necessary to the application\n
 *           pathes, icon, settings ...
 *
 * @enum     Config::UsedConfig
 * @brief    used in perfecting to select used config to test
 *
 *           there is no difference between NS and NS_MERGED, except directories used for tests
 *
 * @var      Config::usedConf
 * @brief    config used for test
 *
 * @var      Config::BASE
 * @brief    old configuration
 *
 * @var      Config::NS
 * @brief    new configuration with multiple dictionaries
 *
 * @var      Config::NS_MERGED
 * @brief    new configuration with multiple dictionaries, test with single dictionary
 */

//}}} --------------------------------------------------------------------------

class Config :                      public QSettings
{
    Q_OBJECT;

public:
    enum                            UsedConfig
    {
        /**/                        BASE, 
        /**/                        NS, 
        /**/                        NS_MERGED, 
    };

    struct                          DicDesc;

public:
    explicit                        Config (QObject * parent = 0);

public:
    static const QString            appName ();
    static const QString            appVersion ();
    static const QString            dicVersion ();

    static const QString            appIconPath ();
    static const QString            appHomePath ();
    static const QString            appWorkPath ();
    static const QString            appExportPath ();
    static const QString            personalDicPath ();
    static const QString            translateDicPath ();
    static const QStringList        dicsPossiblePaths ();
    static const QString            dicFilter ();

    static const QIcon              appIcon ();

public:
    QString                         optionCurrentLanguage () const;
    int                             optionLengthMin ()       const;
    int                             optionWeirdMax ()        const;
    int                             optionDistanceMax ()     const;

public slots:
    void                            setOptionCurrentLanguage (const QString & lang);
    void                            setOptionLengthMin (const int val);
    void                            setOptionWeirdMax (const int val);
    void                            setOptionDistanceMax (const int val);

public:
    static const int                usedConf;
};

//}}} --------------------------------------------------------------------------
//{{{ ..DicDesc ----------------------------------------------------------------

//{{{ class documentation ------------------------------------------------------

/*!
 * @class    Config::DicDesc
 * @brief    dicodor dictionnary descritpion class
 *
 * @var      Config::DicDesc::dir
 * @brief    directory name of text dictionary
 *
 * @var      Config::DicDesc::name
 * @brief    file name (without directory) of text dictionary
 *
 * @var      Config::DicDesc::hashed
 * @brief    complete name of hashed dictionary
 *
 * @var      Config::DicDesc::charSet
 * @brief    char set for this dictionary
 *
 * @var      Config::DicDesc::wordSet
 * @brief    word set for this dictionary
 *
 * @var      Config::DicDesc::wordHash
 * @brief    word hash for this dictionary
 */

//}}} --------------------------------------------------------------------------

struct                              Config::DicDesc
{
    friend QDebug                   operator << (QDebug & s, const DicDesc & d);

    static QHash<QString,QList<DicDesc> > 
        /**/                        list ();
    bool                            hashNeedUpdate ();

    QString                         dir;
    QString                         name;
    QString                         hashed;
    QSet<QChar>                     charSet;
    QSet<QString>                   wordSet;
    QHash<QString, QStringList>     wordHash;
};

QDebug operator << (QDebug & s, const Config::DicDesc & d);

//}}} --------------------------------------------------------------------------
//{{{ inline / template functions ----------------------------------------------
//}}} --------------------------------------------------------------------------
//{{{ .Config ------------------------------------------------------------------

//{{{ function documentation ---------------------------------------------------

/*
 * @fn       Config::appName ()
 * @brief    application for display in "a propos" dialog
 *
 *           some more details
 *
 * @fn       Config::dicFilter ()
 * @brief    dictionary names filters as a string
 * @return   dictionary names filters
 */

//}}} --------------------------------------------------------------------------

inline const QString Config::appName ()          { return "dicodor";  }
inline const QString Config::appVersion ()       { return "12.05.09"; }
inline const QString Config::dicVersion ()       { return "12.05.09"; }

inline const QString Config::appIconPath ()      { return ":/images/appIcon.svg"; }
inline const QString Config::appHomePath ()      { return QString ("%1/.%2/") .arg (QDir::homePath ()) .arg (appName ()); }
inline const QString Config::appWorkPath ()      { return QString ("%1/%2/")  .arg (QDir::tempPath ()) .arg (appName ()); }
inline const QString Config::appExportPath ()    { return appHomePath () + "export/";       }
inline const QString Config::personalDicPath ()  { return appHomePath () + "perso.dic";     }
inline const QString Config::translateDicPath () { return appHomePath () + "translate.dic"; }
inline const QString Config::dicFilter ()        { return "*.dic"; }

inline const QIcon   Config::appIcon ()          { return QIcon (appIconPath ()); }

//}}} --------------------------------------------------------------------------

#endif // CONFIG_H

